package com.hl.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.hl.domain.AfterSalesLogistics;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import com.hl.mapper.AfterSalesServiceMapper;
import com.hl.domain.AfterSalesService;
import com.hl.service.IAfterSalesServiceService;

/**
 * 售后详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@Service
@Primary
public class AfterSalesServiceServiceImpl implements IAfterSalesServiceService 
{
    @Autowired
    private AfterSalesServiceMapper afterSalesServiceMapper;

    /**
     * 查询售后详情
     * 
     * @param id 售后详情主键
     * @return 售后详情
     */
    @Override
    public AfterSalesService selectAfterSalesServiceById(Integer id)
    {
        return afterSalesServiceMapper.selectAfterSalesServiceById(id);
    }

    /**
     * 查询售后详情列表
     * 
     * @param afterSalesService 售后详情
     * @return 售后详情
     */
    @Override
    public List<AfterSalesService> selectAfterSalesServiceList(AfterSalesService afterSalesService)
    {
        return afterSalesServiceMapper.selectAfterSalesServiceList(afterSalesService);
    }

    /**
     * 新增售后详情
     * 
     * @param afterSalesService 售后详情
     * @return 结果
     */
    @Override
    public int insertAfterSalesService(AfterSalesService afterSalesService)
    {
        return afterSalesServiceMapper.insertAfterSalesService(afterSalesService);
    }

    /**
     * 修改售后详情
     * 
     * @param afterSalesService 售后详情
     * @return 结果
     */
    @Override
    public int updateAfterSalesService(AfterSalesService afterSalesService)
    {
        afterSalesService.setUpdateTime(DateUtils.getNowDate());
        return afterSalesServiceMapper.updateAfterSalesService(afterSalesService);
    }

    /**
     * 批量删除售后详情
     * 
     * @param ids 需要删除的售后详情主键
     * @return 结果
     */
    @Override
    public int deleteAfterSalesServiceByIds(Integer[] ids)
    {
        return afterSalesServiceMapper.deleteAfterSalesServiceByIds(ids);
    }

    /**
     * 删除售后详情信息
     * 
     * @param id 售后详情主键
     * @return 结果
     */
    @Override
    public int deleteAfterSalesServiceById(Integer id)
    {
        return afterSalesServiceMapper.deleteAfterSalesServiceById(id);
    }

    /**
     * 新增售后物流信息信息
     *
     * @param afterSalesService 售后详情对象
     */
    public void insertAfterSalesLogistics(AfterSalesService afterSalesService)
    {
        List<AfterSalesLogistics> afterSalesLogisticsList = afterSalesService.getAfterSalesLogisticsList();
        Integer id = afterSalesService.getId();
        if (StringUtils.isNotNull(afterSalesLogisticsList))
        {
            List<AfterSalesLogistics> list = new ArrayList<AfterSalesLogistics>();
            for (AfterSalesLogistics afterSalesLogistics : afterSalesLogisticsList)
            {
                afterSalesLogistics.setServiceNo(String.valueOf(id));
                list.add(afterSalesLogistics);
            }
            if (list.size() > 0)
            {
                afterSalesServiceMapper.batchAfterSalesLogistics(list);
            }
        }
    }
}
